import java.util.Random;
import java.util.Scanner;


public class shootreloadblock {
	public static void main(String[] args){
		Scanner scan = new Scanner (System.in);
		
		System.out.println("--------------Welcome to COWBOY--------------");
		System.out.println("Press your designated number to begin:");
		System.out.println("Your health right now is at 30");
		
		int userHealth = 30;
		int cpuHealth = 30;
	
		
		int counter = 0;
		int cpuCounter = 0;
		
		Random rand = new Random();
		
		
		String a = ("1");
		String b = ("2");
		String c = ("3");
		String x = ("Reload");
		String y = ("Shoot");
		String z = ("Defend");
		
		int counterAI = 0;
		int counterBlock = 0;
		
		
		while ((userHealth > 0 || cpuHealth > 0) && counterBlock <5){
			int cpuChoice = rand.nextInt(3);
			
			if (counterAI == 0){
				cpuChoice = 0;
				counterAI = counterAI +1;
			}
		
			
			System.out.println("1 = Reload, 2 = Shoot, 3 = Defend");
			System.out.println(" ");
			String input = scan.next();
			if (input.equals(a) )
			{ 
				counter = counter+1;
				System.out.println("You have used " + x + "!");
				System.out.println("You now have " + counter + " shot(s)");
				
				if (cpuChoice == 0)
				{
					System.out.println("The CPU has also used reload!");
					cpuCounter++;
					System.out.println("The CPU has " + cpuCounter + " shot(s)");
					
				}
			
				 if (cpuChoice == 1 && cpuCounter>0)
				{
					cpuCounter--;
					System.out.println("The CPU has shot at you! You have been hit!");
					userHealth = userHealth-10;
					System.out.println("The CPU has " + cpuCounter + " shot(s) remaining.");
					System.out.println("Your health is now at " + userHealth + ".");
					
				}
				 if (cpuChoice == 1 && cpuCounter<1)
				{
					cpuChoice = rand.nextInt(3);
				}		
				if (cpuChoice == 2)
				{
					System.out.println("The CPU has used defend!");
					
				}		
			}		

			else if (input.equals(b))
			{
				System.out.println("You have used " + y);
				
				if (counter>0)
				{
					counter=counter-1;
					System.out.println("You have " + counter + " shot(s) remaining");
					
					if (cpuChoice == 0)
				{
					System.out.println("The CPU has used reload while you shot! Nice job!");
					cpuHealth = cpuHealth-10;
					cpuCounter++;
					System.out.println("The CPU's health is now at " + cpuHealth);
					
				}
			
					else if (cpuChoice == 1 && cpuCounter>0)
				{
					cpuCounter--;
					System.out.println("The CPU has shot at you while you shot at him! Both of you lose health!");
					System.out.println("You have " + counter + " shot(s remaining");
					userHealth = userHealth -10;
					System.out.println("Your health is at " + userHealth + "!");
					System.out.println("The CPU has " + cpuCounter + " shot(s) remaining.");
					cpuHealth = cpuHealth - 10;
					System.out.println("The CPU's health is at " + cpuHealth + "!");
					
					
				}
				else if (cpuChoice ==1 && cpuCounter<1)
				{
					cpuChoice = rand.nextInt(3);
				}		
				else if (cpuChoice == 2)
				{
					System.out.println("The CPU has used defend and blocked your shot! Too bad!");
					
				}
				}
				else
					{System.out.println("You don't have any loaded chambers. No shot was fired.");
					{
					if (cpuChoice == 0)
					{
						System.out.println("The CPU has used reload while you fired your empty gun!");
						cpuCounter++;
					}
				
					else if (cpuChoice == 1 && cpuCounter>0)
					{
						cpuCounter--;
						System.out.println("The CPU has shot at you while you fired at him with your empty gun!");
						System.out.println("The CPU has " + cpuCounter + " shot(s) remaining.");
						userHealth = userHealth-10;
						System.out.println("Your health is now at " + userHealth);
						
					}
					else if (cpuChoice ==1 && cpuCounter<1)
					{
						cpuChoice = rand.nextInt(3);
					}		
					else if (cpuChoice == 2)
					{
						System.out.println("The CPU has used defend. Regardless you fired an empty gun! Reload before you shoot!");
					}
				}}}
			else if (input.equals(c)){
				System.out.println("You have used " + z);
				if (cpuChoice == 0)
				{
					System.out.println("The CPU has used reload while you defended! Uh oh!");
					cpuCounter++;
					System.out.println("The cpu has "+ cpuCounter + " shot(s) remaining.");
					
				}
			
				else if (cpuChoice == 1 && cpuCounter>0)
				{
					cpuCounter--;
					System.out.println("The CPU has shot at you! Good thing you defended!!");
					System.out.println("The CPU has " + cpuCounter + " shot(s) remaining.");
					System.out.println("Everyones health remains the same.");
					
				}
				else if (cpuChoice ==1 && cpuCounter<1)
				{
					cpuChoice = rand.nextInt(3);
				}		
				else if (cpuChoice == 2)
				{
					System.out.println("The CPU has also used defend!!");
				}
				}
			
			else{
				System.out.println("Invalid response. Please try again");}	
			
			if (cpuHealth ==0 && userHealth ==0){
				System.out.println("It's a draw, try harder next time!!");
			}
			else if (cpuHealth == 0){
				System.out.println("CONGRATULATIONS YOU WIN!!!!!!");
			}
			else if (userHealth == 0){
				System.out.println("Sorry, you lost. Better luck next time! ");
			}

		
		}
		}
		
		

	}

			


